import cv2
# from modules.utils.api import *
from modules.utils.utils import base64_to_image, image_to_base64
import json
import modules.utils.api as api
import time


if __name__ == '__main__':
    image = cv2.imread("register_img/2a.png")
    # print(image)
    # image = cv2.resize(image, None, fx=0.4, fy=0.4, interpolation=cv2.INTER_AREA)
    # image_64 = image_to_base64(image)
    # print(image_64)
    start1 = time.time()
    vector_json = api.face_register(image, score_reg=0)
    print(vector_json)
    print(time.time() - start1)

    match_vector = json.loads(vector_json)["feature_vector"]  # here match_vector is a list
    # print("register time: {}".format(time.time() - start1))

    match_image = cv2.imread("register_img/2b.png")
    # match_image_2 = cv2.resize(match_image, None, fx=0.4, fy=0.4)
    match_image_64 = image_to_base64(match_image)
    # start2 = time.time()
    # print(match_image_64)
    result = api.match_identity(match_vector, thresh=0.46, score_rec=0.5, image_base64=match_image_64)
    print(result)
    # print("match time: {}".format(time.time() - start2))
    #
    # # print(help(api))


